package top.kaoshanji.p3ch11b;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单-p3ch11b-01：ThreadLocalIdGenerator#main方法
 * author kaoshanji
 * ^_^
 * create time 2025/2/5 17:07
 */
public class ThreadLocalIdGeneratorMain {

    private static final Logger logger = LogManager.getLogger(ThreadLocalIdGeneratorMain.class);

    public static void main(String[] args) {
        logger.info("...代码清单-p3ch11b-01：ThreadLocalIdGenerator#main方法...");

        ThreadLocalIdGeneratorMain main = new ThreadLocalIdGeneratorMain();
        main.startTest();

    }

    public void startTest() {
        for (int i = 0; i < 10; i++) {
            new Thread(new IdDisplay()).start();
        }
    }

    private static class IdDisplay implements Runnable {

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + " ==> " + ThreadLocalIdGenerator.getNext());
            System.out.println(Thread.currentThread().getName() + " ==> " + ThreadLocalIdGenerator.getNext());
        }
    }

}
